//
// Created by ly-zhouxyi on 2024/3/5.
//

#ifndef FFMPEGPLAYER_FFPLAYER_H
#define FFMPEGPLAYER_FFPLAYER_H

#include "FFmpegCallJava.h"
#include "pthread.h"
#include "PlayStatus.h"
#include "AudioDecoder.h"
#include "VideoDecoder.h"

extern "C"
{
#include <libavutil/time.h>
#include "libavformat/avformat.h"
};


class FFPlayer {
public:
    FFmpegCallJava *callJava = NULL;
    const char *url = NULL;
    pthread_t decodeThread;
    AVFormatContext *pFormatCtx = NULL;
    PlayStatus *playStatus = NULL;
    int duration = 0;
    pthread_mutex_t seek_mutex;
    pthread_mutex_t init_mutex;
    bool exit = false;
    AudioDecoder *audioDecoder = NULL;
    VideoDecoder *videoDecoder = NULL;

public:
    FFPlayer(FFmpegCallJava *callJava, PlayStatus *playStatus);

    void decodeFFmpegThread();

    void setDataSource(const char *url);

    void prepare();

    void start();

    void pause();

    void resume();

    void stop();

    void setVolume(float volume);

    void setSpeed(float speed);

    void setPitch(float pitch);
    void setMute(int channel);

    void seek(uint64_t second);

    void setVolumeMute(bool mute);

    int getCurrentVolume();


    int getCodeContext(AVCodecContext ** pAvCodecContext,AVCodecParameters * avCodecParameters);

    ~FFPlayer();
};


#endif //FFMPEGPLAYER_FFPLAYER_H
